package de.hdu.pms.ho.dao;

import org.junit.Test;
import java.util.List;
import de.hdu.pms.ho.model.Kategorie;
import de.hdu.pms.ho.dao.KategorieDao;

/**Test class for {@link KategorieDao} testing
 * This class will test FindById(), FindAll() and testCreate()
 * @author Hendrik Neumann
 *
 */
public class KategorieDaoTest extends AbstractDataAccessTest {
	
	private KategorieDao kategorieDao;
	private String tableName = "Kategorie";
	
	public void setKategorieDao(KategorieDao kategorieDao) {
		this.kategorieDao = kategorieDao;
	}
	
	
	/**Test method for testing the method FindById() in the class 
	 * {@link KategorieDao}. The test data will deleted after use.
	 * 
	 */
	@SuppressWarnings("deprecation")
	@Test
	public void testFindById() {
		String[] tables = {tableName};
		deleteFromTables(tables);
		kategorieDao.create("Pornosuite", 2500.00);
		kategorieDao.create("Billigabsteige", 50);
		List<Kategorie> alleKategorien = kategorieDao.findAll();
		for (Kategorie k : alleKategorien) {
			int id = k.getId();
			Kategorie found = kategorieDao.findById(id);
			assertEquals(k.getBezeichnung(), found.getBezeichnung());
		}
		deleteFromTables(tables);
	}
	
	/**Test method for testing the method FindAll() in the
	 * class {@link KategorieDao}. See also testFindById()
	 * 
	 */
	@Test
	public void testFindAll() {
		//already tested by testFindById()
		testFindById();
	}
	
	/**Test method for testing the method create() in the class 
	 * {@link KategorieDao}. The test data will deleted after use.
	 * 
	 */
	@SuppressWarnings("deprecation")
	@Test
	public void testCreate() {
		String tabellennameKategorie = "kategorie";
		String[] tables = {tableName};
		deleteFromTables(tables);
		kategorieDao.create("Pornosuite", 2500.00);
		int rows = countRowsInTable(tabellennameKategorie);
		assertEquals("Die DB muss eine Zeile enthalten", 1, rows);
	}

}
